﻿using System.Collections.Generic;
using NUnit.Framework;
using StringExt;

namespace DictionaryExt.Test {

    [TestFixture]
    public class ToDictionaryValidPatternSpecial {

        [Test]
        public void EmptyString() {
            const string s = "";
            IDictionary<string, string> result = s.ToDictionary(StringExt.StringExt.RemoveSurroundingBlanks.No);
            Assert.AreEqual(0, result.Count);
        }

        [Test]
        public void NullString() {
            const string s = null;
            IDictionary<string, string> result = s.ToDictionary(StringExt.StringExt.RemoveSurroundingBlanks.No);
            Assert.AreEqual(0, result.Count);
        }

        [Test]
        public void Ending1SepAndBlanksNotRemoved() {
            const string s = "a= ";
            IDictionary<string, string> result = s.ToDictionary(StringExt.StringExt.RemoveSurroundingBlanks.No);
            Assert.IsTrue(result.ContainsKey("a"));
            Assert.AreEqual(" ", result["a"]);
        }

        [Test]
        public void Ending1SepAndBlanksRemoved() {
            const string s = "a= ";
            IDictionary<string, string> result = s.ToDictionary(StringExt.StringExt.RemoveSurroundingBlanks.Yes);
            Assert.IsTrue(result.ContainsKey("a"));
            Assert.AreEqual("", result["a"]);
        }

        [Test]
        public void KeyIsBlankAndNotRemoved() {
            const string s = " =1";
            IDictionary<string, string> result = s.ToDictionary(StringExt.StringExt.RemoveSurroundingBlanks.No);
            Assert.IsTrue(result.ContainsKey(" "));
            Assert.AreEqual("1", result[" "]);
        }

        [Test]
        public void KeyIsBlankAndRemoved() {
            const string s = " =1";
            IDictionary<string, string> result = s.ToDictionary(StringExt.StringExt.RemoveSurroundingBlanks.Yes);
            Assert.IsTrue(result.ContainsKey(""));
            Assert.AreEqual("1", result[""]);
        }

    }
}
